package com.example.match.mui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.example.match.R;
import com.example.match.utils.LoadDialog;
import com.example.mylibrary.CallBack;
import com.example.mylibrary.data.ByteImg;
import com.example.mylibrary.data.DBManager;
import com.example.mylibrary.data.DataDao;
import com.example.mylibrary.data.Item;
import com.example.mylibrary.data.StudentInfo;
import com.example.mylibrary.data.StudentItem;
import com.example.mylibrary.data.StudentListInfo;
import com.example.mylibrary.util.ExlUtils;
import com.example.mylibrary.util.GreenDaoManager;
import com.example.mylibrary.util.Logger;
import com.example.mylibrary.util.SysApplication;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.com.aratek.facelib.AraFaceAuthLib;


public class InfoManageActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
	@Bind(R.id.rv_InfoItemview)
	RecyclerView recyclerView;
	@Bind(R.id.tv_tips)
	TextView tv_tips;
	@Bind(R.id.spinner_sex)
	Spinner spinnerSex;
	@Bind(R.id.spinner_rollcall_status)
	Spinner spinnerRollcallStatus;
	@Bind(R.id.spinner_send_status)
	Spinner spinnerSendStatus;
	@Bind(R.id.spinner_school)
	Spinner spinnerSchool;
	@Bind(R.id.spinner_face_photo)
	Spinner spinnerFacePhoto;
	@Bind(R.id.ed_select)
	EditText stuCodeOrCrad;

	public static final String FILE_IMG = "/sdcard/FP-KTA2203/img/";
	public static final int EXEL_READ_SUCCESS = 0X0;
	public static final int EXEL_READ_FAIL = 0X1;
	private ProgressDialog mProgressDialog;
	private AraFaceAuthLib araFaceAuthLib;
	private Context mContext;
	private Set set = new HashSet();
	private List<String> spinnerSexArr = new ArrayList<>();
	private List<String> spinnerStatusArr = new ArrayList<>();
	private List<String> spinnerSchoolStatusArr = new ArrayList<>();
	private List<String> spinnerSendStatusArr = new ArrayList<>();
	private List<String> spinnerFacePhotoArr = new ArrayList<>();
	private ArrayAdapter<String> spinnerSexAdapter;
	private ArrayAdapter<String> spinnerStatusAdapter;
	private ArrayAdapter<String> spinnerSchoolAdapter;
	private ArrayAdapter<String> spinnerSendStatusAdpter;
	private ArrayAdapter<String> spinnerFacePhotoAdpter;
	private Logger logger;
	//查询到的所有数据   需要展示的数据
	private List<StudentInfo> selectStudentInfos = new ArrayList<>();
	private List<StudentInfo> selectStudentInfos1 = new ArrayList<>();
	//数据源
	private List<StudentListInfo> showStudentInfos = new ArrayList<>();
	//数据源2
	private List<StudentListInfo> showStudentInfos2 = new ArrayList<>();
	private List<StudentListInfo> removeStudentInfos = new ArrayList<>();
	private List<StudentListInfo> positionStudentInfos1 = new ArrayList<>();
	private List<StudentListInfo> positionStudentInfos2 = new ArrayList<>();
	private StudentInfo studentInfo;
	private List<ByteImg> showbyteImg = new ArrayList<>();
	private List<ByteImg> nobyteImg = new ArrayList<>();
	private List<ByteImg> byteImgInfos = new ArrayList<>();
	private ArrayList<StudentListInfo> studentLists;
	private List<StudentListInfo> noDatalist = new ArrayList<>();
	private MyAdapter myAdapter;
	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
				case 0:
					Toast.makeText(mContext, mString, Toast.LENGTH_SHORT);
					break;
				default:
					break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_info_manage);
		ButterKnife.bind(this);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		mContext = this;
		SysApplication.getInstance().addActivity(this);
		initView();
		init();
		initData();
		ExlUtils.getInstance().setExlListener(new ExlUtils.ExlListener() {
			@Override
			public void onExlResponse(final int responseCode) {
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						Log.e("mProgressDialog: ", responseCode + " 0");
						switch (responseCode) {
							case EXEL_READ_SUCCESS:
								mProgressDialog.dismiss();
								break;
							case EXEL_READ_FAIL:
								break;
						}
					}
				});
			}
		});
	}


	private void init() {
		//性别spinner
		spinnerSexArr.add("全部");
		spinnerSexArr.add("男");
		spinnerSexArr.add("女");
		//将可选内容与adapter关联  使用默认样式
		spinnerSexAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerSexArr);
		//设置下拉分项
		spinnerSexAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		//将adapter添加到spinner中
		spinnerSex.setAdapter(spinnerSexAdapter);
		spinnerSex.setOnItemSelectedListener(this);

		//状态spinner
		spinnerStatusArr.add("全部");
		spinnerStatusArr.add("未通过");
		spinnerStatusArr.add("通过");
		//将可选内容与adapter关联  使用默认样式
		spinnerStatusAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerStatusArr);
		//设置下拉分项
		spinnerStatusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		//将adapter添加到spinner中
		spinnerRollcallStatus.setAdapter(spinnerStatusAdapter);
		spinnerRollcallStatus.setOnItemSelectedListener(this);

		spinnerSendStatusArr.add("全部");
		spinnerSendStatusArr.add("未发送");
		spinnerSendStatusArr.add("发送");
		//将可选内容与adapter关联  使用默认样式
		spinnerSendStatusAdpter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerStatusArr);
		//设置下拉分项
		spinnerSendStatusAdpter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		//将adapter添加到spinner中
		spinnerSendStatus.setAdapter(spinnerSendStatusAdpter);
		spinnerSendStatus.setOnItemSelectedListener(this);


		//将set过滤的数据 加入集合里
		spinnerSchoolStatusArr.add("全部");
		spinnerSchoolStatusArr.addAll(set);
		//将可选内容与adapter关联  使用默认样式
		spinnerSchoolAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerSchoolStatusArr);
		//设置下拉分项
		spinnerSchoolAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		//将adapter添加到spinner中
		spinnerSchool.setAdapter(spinnerSchoolAdapter);
		spinnerSchool.setOnItemSelectedListener(this);

		spinnerFacePhotoArr.add("全部");
		spinnerFacePhotoArr.add("有");
		spinnerFacePhotoArr.add("无");
		//将可选内容与adapter关联  使用默认样式
		spinnerFacePhotoAdpter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerFacePhotoArr);
		//设置下拉分项
		spinnerFacePhotoAdpter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		//将adapter添加到spinner中
		spinnerFacePhoto.setAdapter(spinnerFacePhotoAdpter);
		spinnerFacePhoto.setOnItemSelectedListener(this);
	}

	private void initView() {
		recyclerView.setLayoutManager(new LinearLayoutManager(this));
		recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
		mProgressDialog = new ProgressDialog(this);
		mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		mProgressDialog.setIcon(android.R.drawable.ic_dialog_info);
		mProgressDialog.setIndeterminate(false);
		mProgressDialog.setCancelable(false);
		araFaceAuthLib = MainUIActivity.getAraFaceAuthLib();

	}

	private void initData() {
		Date date = null;
		logger = new Logger();
		selectStudentInfos = new ArrayList<>();
		//查询所有学生
		selectStudentInfos = DataDao.queryAll();
		studentInfo = new StudentInfo();
		byteImgInfos = new ArrayList<>();

		for (int i = 0; i < selectStudentInfos.size(); i++) {
			studentInfo = selectStudentInfos.get(i);
			set.add(studentInfo.getSchool());
		}

		studentLists = new ArrayList<>();
		getListDatas();

		showStudentInfos.addAll(studentLists);
		showStudentInfos2.addAll(studentLists);

		if (myAdapter == null) {
			myAdapter = new MyAdapter();
		}
		//构建适配器
		myAdapter.setMyAdapter(showStudentInfos);
		recyclerView.setAdapter(myAdapter);
		tv_tips.setText("共" + myAdapter.getItemCount() + "条");
		mProgressDialog.dismiss();
	}

	private void getListDatas() {
		studentLists.clear();
		for (int j = 0; j < selectStudentInfos.size(); j++) {
			StudentListInfo studentListInfo = new StudentListInfo();
			studentListInfo.setTextTrackNo(j + 1);
			studentListInfo.setTextStuCode(selectStudentInfos.get(j).getStudenCode());
			studentListInfo.setTextStuName(selectStudentInfos.get(j).getStudentName());
			studentListInfo.setTextSex(selectStudentInfos.get(j).getSex());
			studentListInfo.setTextCompany(selectStudentInfos.get(j).getSchool());
			studentListInfo.setTextStateRollCall(selectStudentInfos.get(j).getRollCallState());
			studentListInfo.setTextRollCallTime(selectStudentInfos.get(j).getFinalRollCalltime());
			studentListInfo.setTextSendingState(selectStudentInfos.get(j).getUploadCode());
			studentListInfo.setTextSendingTime(selectStudentInfos.get(j).getUploadTime());
			ByteImg studentImg = DataDao.queryImgIdcard(selectStudentInfos.get(j).getIdCard());
			if (studentImg != null) {
				studentListInfo.setTextStateHead(studentImg.getByteImg());
			}


			studentLists.add(studentListInfo);
		}
	}

	private void getListDatas1() {

		studentLists.clear();
		for (int j = 0; j < selectStudentInfos1.size(); j++) {
			StudentListInfo studentListInfo = new StudentListInfo();
			studentListInfo.setTextTrackNo(j + 1);
			studentListInfo.setTextStuCode(selectStudentInfos1.get(j).getStudenCode());
			studentListInfo.setTextStuName(selectStudentInfos1.get(j).getStudentName());
			studentListInfo.setTextSex(selectStudentInfos1.get(j).getSex());
			studentListInfo.setTextCompany(selectStudentInfos1.get(j).getSchool());
			studentListInfo.setTextStateRollCall(selectStudentInfos1.get(j).getRollCallState());
			studentListInfo.setTextRollCallTime(selectStudentInfos1.get(j).getFinalRollCalltime());
			studentListInfo.setTextSendingState(selectStudentInfos1.get(j).getUploadCode());
			if (selectStudentInfos.get(j).getUploadTime() != null) {
				studentListInfo.setTextSendingTime(selectStudentInfos.get(j).getUploadTime());
			}

			ByteImg studentImg = DataDao.queryImgIdcard(selectStudentInfos.get(j).getIdCard());
			if (studentImg != null) {
				studentListInfo.setTextStateHead(studentImg.getByteImg());
			}
			studentLists.add(studentListInfo);
		}
	}

	@OnClick({R.id.export, R.id.btn_Rollcall})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.export:

				final String codeOrCrad = stuCodeOrCrad.getText().toString().trim();
				selectStudentInfos1.clear();
				selectStudentInfos1 = DataDao.queryInfo(codeOrCrad);
				selectStudentInfos1 = DataDao.queryStuCode(codeOrCrad);
				if (codeOrCrad.isEmpty()) {
					Toast.makeText(this, "请输入考号或者身份证", Toast.LENGTH_SHORT).show();
					showStudentInfos.clear();
					showStudentInfos.addAll(showStudentInfos2);
					myAdapter.notifyDataSetChanged();
					tv_tips.setText("共" + myAdapter.getItemCount() + "条");
				} else if (selectStudentInfos1.size() < 1) {
					Toast.makeText(this, "输入错误", Toast.LENGTH_SHORT).show();
				} else {
					showStudentInfos.clear();
					getListDatas1();
					showStudentInfos.addAll(studentLists);
					myAdapter.notifyDataSetChanged();

					tv_tips.setText("共" + myAdapter.getItemCount() + "条");
					InputMethodManager imm = (InputMethodManager) getSystemService(
							this.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(stuCodeOrCrad.getWindowToken(), 0);
				}

				break;
			case R.id.btn_Rollcall:
				doSearch();
				tv_tips.setText("共" + myAdapter.getItemCount() + "条");
				break;
		}

	}

	private void doSearch() {
		showInputDialog(this);
	}

	private void showInputDialog(Activity activity) {
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setTitle("设置查询条件");
		LayoutInflater inflater = getLayoutInflater();
		View view = inflater.inflate(R.layout.manual_search, null);
		final EditText et_enter_time_start = (EditText) view
				.findViewById(R.id.et_enter_time_start);
		final EditText et_enter_time_end = (EditText) view
				.findViewById(R.id.et_enter_time_end);
		et_enter_time_start.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				DateTimePickDialog dateTimePicKDialog = new DateTimePickDialog(
						InfoManageActivity.this, getTime());
				dateTimePicKDialog.dateTimePicKDialog(et_enter_time_start);
			}
		});

		et_enter_time_end.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				DateTimePickDialog dateTimePicKDialog = new DateTimePickDialog(
						InfoManageActivity.this, getTime());
				dateTimePicKDialog.dateTimePicKDialog(et_enter_time_end);
			}
		});

		builder.setCancelable(false);
		builder.setView(view);
		builder.setPositiveButton("查询", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				final String enter_time_start = et_enter_time_start.getText()
						.toString().trim();
				final String enter_time_end = et_enter_time_end.getText()
						.toString().trim();
				Log.e("enter_time", enter_time_start + "-------" + enter_time_end + "-------");
				selectStudentInfos1.clear();
				selectStudentInfos1 = DataDao.find(enter_time_start, enter_time_end);
				if (selectStudentInfos1 == null) {
					showStudentInfos.clear();
					showStudentInfos.addAll(studentLists);
					myAdapter.notifyDataSetChanged();
					Toast.makeText(mContext, "无数据", Toast.LENGTH_SHORT).show();
				} else if (selectStudentInfos1 != null) {
					showStudentInfos.clear();
					getListDatas1();
					showStudentInfos.addAll(studentLists);
					myAdapter.notifyDataSetChanged();
				}

				tv_tips.setText("共" + myAdapter.getItemCount() + "条");
			}
		});

		builder.show();
	}

	private String getTime() {
		Calendar c = Calendar.getInstance(Locale.CHINA);
		c.setTime(new Date());
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH) + 1;
		int day = c.get(Calendar.DAY_OF_MONTH);
		int hour = c.get(Calendar.HOUR_OF_DAY);
		int minute = c.get(Calendar.MINUTE);
		int second = c.get(Calendar.SECOND);
		String mYear = String.valueOf(year);
		String mMonth = month <= 9 ? "0" + month : String.valueOf(month);
		String mDay = day <= 9 ? "0" + day : String.valueOf(day);
		String mHour = hour <= 9 ? "0" + hour : String.valueOf(hour);
		String mMinute = minute <= 9 ? "0" + minute : String.valueOf(minute);
		String mSecond = second <= 9 ? "0" + second : String.valueOf(second);
		return mYear + "-" + mMonth + "-" + mDay + " " + mHour + ":" + mMinute
				+ ":" + mSecond;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.menu_manage_activitybar, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.btn_leadingInfo:
				Intent intent = new Intent(InfoManageActivity.this,
						FilePickActivity2.class);
				startActivityForResult(intent, 0);
				break;
			case R.id.btn_insertfaceImg:
				mProgressDialog.setTitle(getString(R.string.loading));
				mProgressDialog.setMessage(getString(R.string.preparing_device));
				mProgressDialog.show();
				new Thread() {
					@Override
					public void run() {
						super.run();
						final List<String> list = new ArrayList();
						//循环此目录下所有图片
						File scanner5Directory = new File(FILE_IMG);
						if (scanner5Directory.isDirectory()) {
							for (File file : scanner5Directory.listFiles()) {
								String path = file.getAbsolutePath();
								if (path.endsWith(".jpg") || path.endsWith(".png") || path.endsWith(".jpeg")) {
									list.add(path);
								}
							}
						}

						if (list.size() < 1) {
							mProgressDialog.dismiss();
							runOnUiThread(new Runnable() {
								@Override
								public void run() {
									Toast.makeText(mContext, "此路径下无照片", Toast.LENGTH_SHORT).show();
								}
							});
						}
						int j = 0;
						for (final String sFile : list) {

							j++;
							Bitmap bm1 = BitmapFactory.decodeFile(sFile);
							String s = sFile;
							//去除多余路径保留图片名称
							String temp[] = s.replaceAll("\\\\", "/").split("/");
							String fileName = "";
							if (temp.length > 1) {
								fileName = temp[temp.length - 1];
							}
							//去除扩展名
							String prefix = fileName.substring(0, fileName.lastIndexOf("."));

							Log.e("path: ", prefix + "");

							Log.e("BitmapTime------->", bm1 + "");
							//将图片转换成byte[]
							byte[] cardData = araFaceAuthLib.getFeature(bm1);
							Log.e("cardDataTime-------> ", cardData + "");
							ByteImg byteImg = new ByteImg();

							byteImg.setStudentCode(prefix);
							byteImg.setByteImg(cardData);
							//将图片保存在数据库
							DataDao.insertImg(byteImg);
							if (j == list.size()) {
								Log.e("dismiss: ", j + "-----" + list.size());
								mProgressDialog.dismiss();
								break;
							}
						}
					}
				}.start();
				break;
			case R.id.btn_deleteAll:
				GreenDaoManager greenDaoManager = new GreenDaoManager(this);
				greenDaoManager.deleSQL();
				break;
			case R.id.btn_Test:
				String code = "1388";
				StudentInfo info = DBManager.getInstance(mContext).queryStudentId(code);
				Log.e("onClick:stu id ", info.getStudentID() + "");
				List<StudentItem> studentItem = DBManager.getInstance(mContext).queryStudentItem(info.getStudentID());
				Log.e("onClick: item name ", studentItem.get(0).getItemID() + "");
				for (StudentItem s : studentItem) {
					List<Item> item1 = DBManager.getInstance(mContext).queryItemName(s.getItemID());
					//   Log.e( "onClick: itemid",item.get(0).getItemName()+"" );
					for (Item items : item1) {
						Log.e("onClick: itemname", items.getItemName());
					}
				}
				break;

		}
		return super.onOptionsItemSelected(item);

	}

	private String mString = "";

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (resultCode == 0) {
			final String filePath = data.getStringExtra("filePath");
			if (null != filePath && filePath.length() > 0) {
				Toast.makeText(this, "" + filePath, Toast.LENGTH_SHORT).show();
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
					   /* mProgressDialog.setTitle(getString(R.string.loading));
					    mProgressDialog.setMessage(getString(R.string.preparing_device));
                        mProgressDialog.show();*/
						LoadDialog.showDialog(mContext, getString(R.string.preparing_device));
						ExlUtils.getInstance().readExlData3(InfoManageActivity.this, filePath, new CallBack() {
							@Override
							public void onSucess(Object o) {
								LoadDialog.dismssDialog();
							}

							@Override
							public void onFail(String string) {
								mString = string;
								LoadDialog.dismssDialog();
								mHandler.sendEmptyMessage(0);
//								Toast.makeText(mContext, string, Toast.LENGTH_SHORT);
							}
						});

					}
				});
			} else {
				Toast.makeText(InfoManageActivity.this, "未选择文件",
						Toast.LENGTH_SHORT).show();
			}
		}

	}


	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
		switch (parent.getId()) {
			case R.id.spinner_sex:
				String sex = (String) parent.getSelectedItem();
				positionStudentInfos1.clear();
				positionStudentInfos2.clear();
				for (int j = 0; j < showStudentInfos2.size(); j++) {
					if (showStudentInfos2.get(j).getTextSex() == 0) {
						positionStudentInfos1.add(showStudentInfos2.get(j));
					}
					if (showStudentInfos2.get(j).getTextSex() == 1) {
						positionStudentInfos2.add(showStudentInfos2.get(j));
					}
				}
				if (position == 0) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
					showStudentInfos.addAll(positionStudentInfos2);

				}
				if (position == 1) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
				}
				if (position == 2) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos2);
				}
				myAdapter.notifyDataSetChanged();
				tv_tips.setText("共" + myAdapter.getItemCount() + "条");
				break;
			case R.id.spinner_rollcall_status:
				positionStudentInfos1.clear();
				positionStudentInfos2.clear();
				for (int j = 0; j < showStudentInfos2.size(); j++) {
					if (showStudentInfos2.get(j).getTextStateRollCall() == 0) {
						positionStudentInfos1.add(showStudentInfos2.get(j));
					}
					if (showStudentInfos2.get(j).getTextStateRollCall() == 1) {
						positionStudentInfos2.add(showStudentInfos2.get(j));
					}
				}
				if (position == 0) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
					showStudentInfos.addAll(positionStudentInfos2);
				}
				if (position == 1) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
				}
				if (position == 2) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos2);
				}
				myAdapter.notifyDataSetChanged();
				tv_tips.setText("共" + myAdapter.getItemCount() + "条");
				break;
			case R.id.spinner_send_status:
				positionStudentInfos1.clear();
				positionStudentInfos2.clear();
				for (int j = 0; j < showStudentInfos2.size(); j++) {
					if (showStudentInfos2.get(j).getTextSendingState() == 0) {
						positionStudentInfos1.add(showStudentInfos2.get(j));
					}
					if (showStudentInfos2.get(j).getTextSendingState() == 1) {
						positionStudentInfos2.add(showStudentInfos2.get(j));
					}

				}
				if (position == 0) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
					showStudentInfos.addAll(positionStudentInfos2);
				}
				if (position == 1) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
				}
				if (position == 2) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos2);
				}
				myAdapter.notifyDataSetChanged();
				tv_tips.setText("共" + myAdapter.getItemCount() + "条");


				break;
			case R.id.spinner_school:
				removeStudentInfos.clear();
				for (int j = 0; j < showStudentInfos2.size(); j++) {
					if (showStudentInfos2.get(j).getTextCompany().equals(spinnerSchoolStatusArr.get((int) id))) {
						removeStudentInfos.add(showStudentInfos2.get(j));
					}
				}
				if (position == 0) {
					showStudentInfos.clear();
					showStudentInfos.addAll(showStudentInfos2);
					myAdapter.notifyDataSetChanged();
					tv_tips.setText("共" + myAdapter.getItemCount() + "条");
				} else {
					showStudentInfos.clear();
					showStudentInfos.addAll(removeStudentInfos);
					myAdapter.notifyDataSetChanged();
					tv_tips.setText("共" + myAdapter.getItemCount() + "条");
				}


				break;
			case R.id.spinner_face_photo:
				positionStudentInfos1.clear();
				positionStudentInfos2.clear();
				for (int j = 0; j < showStudentInfos2.size(); j++) {
					if (showStudentInfos2.get(j).getTextStateHead() != null) {
						positionStudentInfos1.add(showStudentInfos2.get(j));
					} else {
						positionStudentInfos2.add(showStudentInfos2.get(j));
					}

				}
				if (position == 0) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
					showStudentInfos.addAll(positionStudentInfos2);
				}
				if (position == 1) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos1);
				}
				if (position == 2) {
					showStudentInfos.clear();
					showStudentInfos.addAll(positionStudentInfos2);
				}
				myAdapter.notifyDataSetChanged();
				tv_tips.setText("共" + myAdapter.getItemCount() + "条");
				break;
		}
	}

	@Override
	public void onNothingSelected(AdapterView<?> parent) {

	}


	class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
		private List<StudentListInfo> selectStudentInfos;


		public void setMyAdapter(List<StudentListInfo> selectStudentInfos) {
			this.selectStudentInfos = selectStudentInfos;
		}


		@Override
		public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
			InfoViewHolder infoViewHolder = new InfoViewHolder(LayoutInflater.from(InfoManageActivity.this).inflate(R.layout.item_list_view, parent, false));
			return infoViewHolder;

		}

		@Override
		public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
			InfoViewHolder infoViewHolder = (InfoViewHolder) holder;

			infoViewHolder.textTrackNo.setText(String.valueOf(position + 1));
			infoViewHolder.textStuCode.setText(selectStudentInfos.get(position).getTextStuCode());
			infoViewHolder.textStuName.setText(selectStudentInfos.get(position).getTextStuName());
			if (selectStudentInfos.get(position).getTextSex() == 0) {
				infoViewHolder.textSex.setText("男");
			} else {

				infoViewHolder.textSex.setText("女");
			}
			infoViewHolder.textCompany.setText(selectStudentInfos.get(position).getTextCompany());
			if (selectStudentInfos.get(position).getTextStateRollCall() == 1) {
				infoViewHolder.textStateRollCall.setText("通过");
			} else {
				infoViewHolder.textStateRollCall.setText("未通过");

			}
			if (selectStudentInfos.get(position).getTextSendingState() == 1) {
				infoViewHolder.textSendingState.setText("发送");
			} else {

				infoViewHolder.textSendingState.setText("未发送");
			}

			infoViewHolder.textRollCallTime.setText(selectStudentInfos.get(position).getTextRollCallTime());
			infoViewHolder.textSendingTime.setText(selectStudentInfos.get(position).getTextSendingTime());

			if (selectStudentInfos.get(position).getTextStateHead() != null) {
				infoViewHolder.textStateHead.setText("有数据");
			} else {

				noDatalist.add(selectStudentInfos.get(position));
				infoViewHolder.textStateHead.setText("无数据");
			}

		}

		@Override
		public int getItemCount() {
			return selectStudentInfos.size();
		}


		class InfoViewHolder extends RecyclerView.ViewHolder {
			@Bind(R.id.tv_trackNo)
			TextView textTrackNo;
			@Bind(R.id.tv_studentCode)
			TextView textStuCode;
			@Bind(R.id.tv_studentName)
			TextView textStuName;
			@Bind(R.id.tv_sex)
			TextView textSex;
			@Bind(R.id.tv_company)
			TextView textCompany;
			@Bind(R.id.tv_state_head)
			TextView textStateHead;
			@Bind(R.id.tv_state_rollcall)
			TextView textStateRollCall;
			@Bind(R.id.tv_rollcall_time)
			TextView textRollCallTime;
			@Bind(R.id.tv_sending_state)
			TextView textSendingState;
			@Bind(R.id.tv_sending_time)
			TextView textSendingTime;

			public InfoViewHolder(View itemView) {
				super(itemView);
				ButterKnife.bind(this, itemView);
			}
		}

	}


}
